package com.oa.service.impl;

import com.oa.vo.Page;
import com.oa.pojo.Employee;
import com.oa.mapper.EmployeeMapper;
import com.oa.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void addEmployeeMapper(Employee employee) {
        employeeMapper.addEmployeeMapper(employee);
    }

    @Override
    public void delEmployee(Integer emloyeeId) {
        employeeMapper.delEmployee(emloyeeId);
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeMapper.updateEmployee(employee);
    }

    @Override
    public List<Employee> getEmployeeList() {
        return employeeMapper.getEmployeeList();
    }

    @Override
    public Page getEmployeePage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Employee> employeeList = employeeMapper.getEmployeeList();
        Page page = new Page();
        PageInfo<Employee> pageInfo = new PageInfo<>(employeeList);
        page.setPageCount(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());
        page.setObject(pageInfo.getList());
        return page;
    }

    @Override
    public Employee getEmployee(Integer employeeId) {
        return employeeMapper.getEmployee(employeeId);
    }
}
